package com.shoe.controller;

import com.shoe.service.AandUCouService;
import com.shoe.util.ResultUtil;
import com.shoe.vo.AandUCouVo;
import com.shoe.vo.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("admin")
public class AandUCouController {

    @Autowired
    AandUCouService andUCouService;

    @Autowired
    ResultUtil resultUtil;

    @GetMapping("selectAandUCou")
    public ResponseResult selectAandUCou(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit, Integer userId) {

        List<AandUCouVo> aUCouPage = andUCouService.selectAandUCouPage((page - 1) * limit, limit, userId);
        List<AandUCouVo> aUCou = andUCouService.selectAandUCou(userId);

        if (null != aUCouPage && aUCouPage.size() > 0) {
            return resultUtil.getResponseResult(0, "", aUCou.size(), aUCouPage);
        } else {
            return resultUtil.getResponseResult(2, "没有结果");
        }
    }

    @GetMapping("deletaucou")
    public ResponseResult deleteAuCouByUcId(Integer usercouponId){
        int affRow = andUCouService.deleteAandUCou(usercouponId);
        if(affRow > 0){
            return resultUtil.getResponseResult(0,"",affRow);
        }else {
            return resultUtil.getResponseResult(2,"操作失败",affRow);
        }
    }
}
